﻿using System.Web;
using System.Web.Script.Serialization;
using TransFormer.Web.admin.WebModel;
using System.Web.SessionState;

namespace TransFormer.Web.admin.AdminAshx
{
    /// <summary>
    /// UserInfos 的摘要说明
    /// </summary>
    public class UserInfos : IHttpHandler,IRequiresSessionState
    {
        private BLL.UserInfo _bll = new BLL.UserInfo();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int pageIndex = 1;
            int pageSize = 10;

            int.TryParse(context.Request["rows"], out pageSize);
            int.TryParse(context.Request["page"], out pageIndex);

            var list = _bll.GetListByPage(string.Empty, "Id", (pageIndex - 1) * pageSize + 1, pageIndex * pageSize);
            var modelList = _bll.DataTableToList(list.Tables[0]);
            var data = new EzuiModel<Model.UserInfo> {rows = modelList.ToArray()};
            data.total = _bll.GetRecordCount(string.Empty).ToString();
            var jz = new JavaScriptSerializer();
            var jsonData = jz.Serialize(data);
            context.Response.Write(jsonData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}